<?php
class CoreCache extends CFileCache {

    /**
	 * Initializes the application component.
	 * This method overrides the parent implementation by setting default cache key prefix.
	 */
	public function init()
	{
		parent::init();
	}

	/**
	 * @param string $key a key identifying a value to be cached
	 * @return sring a key generated from the provided key which ensures the uniqueness across applications
	 */
	protected function generateUniqueKey($key)
	{
		return $this->keyPrefix.$key;
	}

    public function setKeyPrefix($keyPrefix)
    {
        if(isset($keyPrefix))
        {
            $this->keyPrefix = $keyPrefix;
        }
    }

    public static function deleteCache($cacheId, $area='all')
    {
        if(isset($cacheId))
        {
            if($area == 'all')
            {
                //Delete front-end config cache
                Yii::app()->cache->keyPrefix = "front";
                Yii::app()->cache->delete($cacheId);

                //Delete back-end config cache
                Yii::app()->cache->keyPrefix = "admin";
                Yii::app()->cache->delete($cacheId);
            }
            else
            {
                //Delete back-end config cache
                Yii::app()->cache->keyPrefix = $area;
                Yii::app()->cache->delete($cacheId);
            }
            return true;
        }

        return false;
    }
}
?>
